home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / compass1 / compass.jar / Compass.class (.txt) next >
Encoding:
Java Class File  |  2002-10-24  |  3.1 KB  |  88 lines

  1. import javax.microedition.lcdui.Canvas;
  2. import javax.microedition.lcdui.Command;
  3. import javax.microedition.lcdui.CommandListener;
  4. import javax.microedition.lcdui.Display;
  5. import javax.microedition.lcdui.Displayable;
  6. import javax.microedition.lcdui.Form;
  7. import javax.microedition.midlet.MIDlet;
  8.  
  9. public class Compass extends MIDlet implements CommandListener {
  10.    Display display;
  11.    Command northCmd = new Command("North", 4, 1);
  12.    Command southCmd = new Command("South", 3, 1);
  13.    Command yesCmd = new Command("Yes", 4, 1);
  14.    Command noCmd = new Command("No", 3, 1);
  15.    Command okCmd = new Command("OK", 4, 1);
  16.    Command exitCmd = new Command("Exit", 7, 1);
  17.    boolean northern = true;
  18.    boolean daylightSaving;
  19.  
  20.    public void startApp() {
  21.       this.display = Display.getDisplay(this);
  22.       this.getHemispere();
  23.    }
  24.  
  25.    public void getHemispere() {
  26.       Form form = new Form("");
  27.       form.append("Are you in the North or Southern Hemispere?");
  28.       ((Displayable)form).addCommand(this.northCmd);
  29.       ((Displayable)form).addCommand(this.southCmd);
  30.       ((Displayable)form).setCommandListener(this);
  31.       this.display.setCurrent(form);
  32.    }
  33.  
  34.    public void getDaylightSaving() {
  35.       Form form = new Form("");
  36.       form.append("Are you in daylight savings time?");
  37.       ((Displayable)form).addCommand(this.yesCmd);
  38.       ((Displayable)form).addCommand(this.noCmd);
  39.       ((Displayable)form).setCommandListener(this);
  40.       this.display.setCurrent(form);
  41.    }
  42.  
  43.    public void showInstructions() {
  44.       Form form = new Form("");
  45.       form.append("Now lie the phone flat so that the top of the phone points towards the sun.");
  46.       ((Displayable)form).addCommand(this.okCmd);
  47.       ((Displayable)form).setCommandListener(this);
  48.       this.display.setCurrent(form);
  49.    }
  50.  
  51.    public void showCompas() {
  52.       Canvas canvas = new CompassCanvas(this);
  53.       ((Displayable)canvas).addCommand(this.exitCmd);
  54.       ((Displayable)canvas).setCommandListener(this);
  55.       this.display.setCurrent(canvas);
  56.    }
  57.  
  58.    public void commandAction(Command c, Displayable s) {
  59.       if (c == this.northCmd) {
  60.          this.northern = true;
  61.          this.getDaylightSaving();
  62.       } else if (c == this.southCmd) {
  63.          this.northern = false;
  64.          this.getDaylightSaving();
  65.       } else {
  66.          if (c == this.yesCmd) {
  67.             this.daylightSaving = true;
  68.             this.showInstructions();
  69.          } else if (c == this.noCmd) {
  70.             this.daylightSaving = false;
  71.             this.showInstructions();
  72.          } else if (c == this.okCmd) {
  73.             this.showCompas();
  74.          } else if (c == this.exitCmd) {
  75.             this.destroyApp(false);
  76.             ((MIDlet)this).notifyDestroyed();
  77.          }
  78.  
  79.       }
  80.    }
  81.  
  82.    public void pauseApp() {
  83.    }
  84.  
  85.    public void destroyApp(boolean unconditional) {
  86.    }
  87. }
  88.